<template>
    <h2 style="text-align: center ">注册</h2>
    <table border="1">
        <tr>
            <td>账号</td>
            <td>
                <input type="text" v-model="info.Uname">
            </td>
        </tr>
        <tr>
            <td>密码</td>
            <td>
                <input type="password" v-model="info.Upwd">
            </td>
        </tr>
        <tr>
            <td></td>
            <td>
                <input type="button" value="注册" @click="Enroll()">
            </td>
        </tr>
    </table>
</template>
<script setup lang="ts">
import {ref} from 'vue'
import {useRouter} from 'vue-router'
import axios from 'axios'

const router = useRouter()

const info =ref({
    Uname:"",
    Upwd:""
})

const Enroll = () => {
    if(info.value.Uname==""){
        alert("用户账号不能为空")
        return
    }
    if(info.value.Upwd==""){
        alert("用户密码不能为空")
        return
    }
    axios({
        url:"http://localhost:52342/api/User/UserEnroll",
        method:"post",
        data:info.value
    })
    .then((res) => {
        if(res.data==-1){
            alert("用户账号不能重复")
            return
        }else if(res.data>0){
            alert("注册成功")
            router.push("/UserLogin")
        }else{
            alert("注册失败")
            return
        }
    })
    .catch((err) => {
        console.log(err)
    })
}





</script>


